<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPE html>
<html>
<head>
<title>订单统计</title>
<jsp:include page="../../views/layout/inc.jsp"></jsp:include>
<link rel="stylesheet" href="/css/core/easyui/easyui-rtl.css?v=201505241044"/>
<style type="text/css">
	.tdh{font-weight: bold;}
</style>
<%-- <c:if test="${fn:contains(sessionInfo.resourceList, '/propertyCompanyController/editPage')}"> --%>
	<script type="text/javascript">
		$.canEdit = true;
	</script>
<%-- </c:if> --%>
<%-- <c:if test="${fn:contains(sessionInfo.resourceList, '/propertyCompanyController/delete')}"> --%>
	<script type="text/javascript">
		$.canDelete = true;
	</script>
<%-- </c:if> --%>
<script type="text/javascript">
	var url = window.location.href;
	var type = url.split('=')[1];
	var dataGrid;
	$(function() {
		var typeCon = "";
		if (type) {
			typeCon = '?orderType=' + type;
		}
		dataGrid = $('#dataGrid').datagrid({
			singleSelect : true,
			url : '/orderStatisticsController/dataGrid' + typeCon,
			fit : true,
			fitColumns : false,
			border : false,
			pagination : true,
			idField : 'id',
			pageSize : 10,
			pageList : [ 10, 20, 30, 40, 50 ],
			sortName : 'gmtModify',
			sortOrder : 'desc',
			checkOnSelect : false,
			selectOnCheck : false,
			nowrap : true,
			columns : [ [  {
				field : 'outBizNum',
				title :'订单号',
				width : 100
			},{
				field : 'name',
				title :'订单名称',
				width : 120
			},{
				field : 'orderType',
				title :'订单类型',
				width : 100,
				formatter:function(val,rec){ 
					if(val == 1) {
						return '代收快递';
					}else if(val == 2) {
						return '代发快递';
					}else if(val == 3) {
						return '代洗衣物';
					}else {
						return '未知';
					}
				}
			},{
				field : 'residenceName',
				title :'小区名称',
				width : 100
			},{
				field : 'courierType',
				title :'快递类型',
				width : 100,
				formatter:function(val,rec){ 
					if(val == 1) {
						return '普通';
					}else if(val == 2) {
						return '及时';
					}else {
						return '未知';
					}
				}
			},{
				field : 'companyName',
				title :'快递公司/洗衣店',
				width : 100
			},{
				field : 'srcAccountName',
				title :'发件人',
				width : 100
			},{
				field : 'srcMobile',
				title :'发件人电话',
				width : 100
			},{
				field : 'desAccountName',
				title :'收件人',
				width : 100
			},{
				field : 'desMobile',
				title :'收件人电话',
				width : 100
			},{
				field : 'desAreaDetail',
				title :'收件地址',
				width : 200,
				formatter:function(val,rec){ 
					return rec.desProvinceName + rec.desCityName + rec.desDistrictName + val;
				}
			},{
				field : 'srcAreaDetail',
				title :'发件地址',
				width : 200,
				formatter:function(val,rec){ 
					return rec.srcProvinceName + rec.srcCityName + rec.srcDistrictName + val;
				}
			},{
				field : 'amount',
				title :'订单费用（元）',
				width : 100,
				formatter:function(val,rec){ 
					if(val != null) {
						return val/100;
					}
				}
			},{
				field : 'status',
				title :'状态',
				width : 100,
				formatter:function(val,rec){ 
					var type = rec.orderType;
					if (type) {
						if(type == 1) {
							if(val == 1) {
								return '待取';
							}else if(val == 2) {
								return '完成';
							}else if(val == 3) {
								return '<span style="color:red">关闭</span>';
							}else if(val == 4) {
								return '删除';
							}else {
								return '未知';
							}
						}else if(type == 2) {
							if(val == 1) {
								return '待处理';
							}else if(val == 2) {
								return '已发件（完成）';
							}else if(val == 3) {
								return '<span style="color:red">关闭</span>';
							}else if(val == 4) {
								return '删除';
							}else if(val == 5) {
								return '已取件';
							}else{
								return '未知';
							}
						}else if(type == 3) {
							if(val == 1) {
								return '待处理';
							}else if(val == 2) {
								return '完成';
							}else if(val == 3) {
								return '<span style="color:red">关闭</span>';
							}else if(val == 4) {
								return '删除';
							}else if(val == 5) {
								return '已取件';
							}else if(val == 7) {
								return '已送洗';
							}else if(val == 8) {
								return '待取';
							}else{
								return '未知';
							}
						}else {
							return '未知';
						}
					}
					if(val == 1) {
						return '待处理';
					}else if(val == 2) {
						return '<span style="color:green">已发件</span>';
					}else if(val == 3) {
						return '<span style="color:red">关闭</span>';
					}else if(val == 5) {
						return '已取件';
					}else {
						return '未知';
					}
				}
			},{
				field : 'gmtCreate',
				title : '创建时间',
				width : 150,
				formatter:function(val,rec){ 
					 var unixTimestamp = new Date(val);  
                     return unixTimestamp.format("yyyy-MM-dd hh:mm:ss");  
				}
			}, {
				field : 'gmtModify',
				title : '修改时间',
				width : 150,
				formatter:function(val,rec){ 
					if(val == "" || val == null) {
						return "";
					}
					 var unixTimestamp = new Date(val);  
                    return unixTimestamp.format("yyyy-MM-dd hh:mm:ss");  
				}
			} ] ],
			toolbar : '#toolbar',
			onLoadSuccess : function() {
				$('#searchForm table').show();
				parent.$.messager.progress('close');
				$(this).datagrid('tooltip');
			},
			onRowContextMenu : function(e, rowIndex, rowData) {
				e.preventDefault();
				$(this).datagrid('unselectAll').datagrid('uncheckAll');
				$(this).datagrid('selectRow', rowIndex);
			} 
		});
		
		$.ajax({
			type:'post',
			url:'/residenceController/combobox',
			success:function(result) {
				$('#residenceId').combobox({
					data : result,
				    panelHeight:'auto',
				    editable:false
				});
				sessionStorage.setItem("comboboxExpress", JSON.stringify(result));
			},
			dataType:'json'
		});
		
		$('#companyId').combobox({
			data : [],
		    panelHeight:'auto',
		    editable:false
		});
		
		$('#orderType').combobox({
			data : [{"value":1,"text":"代收快递"},
			        {"value":2,"text":"代发快递"},
			        {"value":3,"text":"代洗衣物"}],
		    panelHeight:'auto',
		    editable:false,
		    onSelect: function(record) {
		    	setCom(record.value);
		    }
		});
		
		$('#status').combobox({
			data : [],
		    panelHeight:'auto',
		    editable:false
		});
		
		if (type) {
			$('#orderType').combobox('setValue', type);
			setCom(type);
		}
		count();
	});
	
	function setCom(value) {
		if (value == 3) {
    		$.ajax({
    			type:'post',
    			url:'/companyLaundryController/getCombobox',
    			success:function(result) {
    				$('#companyId').combobox({
    					data : result,
    				    panelHeight:'auto',
    				    editable:false
    				});
    				sessionStorage.setItem("comboboxExpress", JSON.stringify(result));
    			},
    			dataType:'json'
    		});
    	} else {
    		$.ajax({
    			type:'post',
    			url:'/companyExpressController/getCombobox',
    			success:function(result) {
    				$('#companyId').combobox({
    					data : result,
    				    panelHeight:'auto',
    				    editable:false
    				});
    				sessionStorage.setItem("comboboxExpress", JSON.stringify(result));
    			},
    			dataType:'json'
    		});
    	}
    	if (value == 1) {
    		$('#status').combobox({
    			data : [{"value":1,"text":"待取"},
    			        {"value":2,"text":"完成"},
    			        {"value":3,"text":"关闭"},
    			        {"value":4,"text":"删除"}]
    		});
    	} else if (value == 2) {
    		$('#status').combobox({
    			data : [{"value":1,"text":"待处理"},
    			        {"value":2,"text":"已发件（完成）"},
    			        {"value":3,"text":"关闭"},
    			        {"value":4,"text":"删除"},
    			        {"value":5,"text":"已取件"}]
    		});
    	} else if (value == 3) {
    		$('#status').combobox({
    			data : [{"value":1,"text":"待处理"},
    			        {"value":2,"text":"完成"},
    			        {"value":3,"text":"关闭"},
    			        {"value":4,"text":"删除"},
    			        {"value":5,"text":"已取件"},
    			        {"value":7,"text":"已送洗"},
    			        {"value":8,"text":"待取"}]
    		});
    	} else {
    		$('#status').combobox({
    			data : [],
    		    panelHeight:'auto',
    		    editable:false
    		});
    	}
	}

	function searchFun() {
		dataGrid.datagrid('load', $.serializeObject($('#searchForm')));
		count();
	}
	
	function cleanFun() {
		$('#searchForm input').val('');
		dataGrid.datagrid('load', {});
		count();
	}
	
	function count() {
		$.post("/orderStatisticsController/getCountAll", 
				$.serializeObject($('#searchForm')), function(result) {
			if (result) {
				$('#orderCount').html(result.count);
				$('#orderFee').html(result.fee/100);
			}
		}, 'json');
	}
</script>
</head>
<body>
	<div class="easyui-layout" data-options="fit : true,border : false">
		<div data-options="region:'north',title:'查询条件',border:false" style="height: 150px; overflow: hidden;">
			<form id="searchForm">
				<table class="table table-hover table-condensed" >
					<tr>
						<td class="tdh">订单类型</td>
						<td>
							<input id="orderType" name="orderType" />
						</td>
						<td class="tdh">小区</td>
						<td><input name="residenceId" id="residenceId" /></td>
					</tr>
					<tr>
						<td class="tdh">订单状态</td>
						<td>
							<input id="status" name="status" />
						</td>
						<td class="tdh">快递公司/洗衣店</td>
						<td><input name="companyId" id="companyId" /></td>
					</tr>
					<tr>
						<td class="tdh">时间</td>
						<td><input name="startOrder" id="startOrder" placeholder="点击选择时间" class="Wdate" style="width:150px" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',maxDate:'#F{$dp.$D(\'endOrder\') || \'%y-%M-%d\'}'})"/></td>
						<td colspan="2">至 <input name="endOrder" id="endOrder" placeholder="点击选择时间" class="Wdate" style="width:150px" onclick="WdatePicker({dateFmt:'yyyy-MM-dd',minDate:'#F{$dp.$D(\'startOrder\') || \'%y-%M-%d\'}'})"/></td>
					</tr>
				</table>
			</form>
		</div>
		<div data-options="region:'center',border:false">
			<table id="dataGrid"></table>
		</div>
	</div>
	<div id="toolbar" style="display: none;">
		<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-search',plain:true" onclick="searchFun();">提交查询</a>
		<a href="javascript:void(0);" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true" onclick="cleanFun();">重置查询</a>
		<span style="float: right;height: 26px;text-align: center;line-height: 26px">订单数量：<b id="orderCount"></b>，费用合计：<b id="orderFee"></b>元</span>
	</div>
</body>
</html>